﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace DuAn
{
    public class DataAccess
    {
        #region "variable"
        public string strConnect;
        private SqlConnection conn;
        private string strError = "";
        #endregion

        #region "Properties"
        public string Error
        {
            get { return strError; }
            set { strError = value; }
        }
        #endregion
        public DataAccess()
        {
            //
            // TODO: Add constructor logic here
            //
            strConnect = "server=(local);database=DangNhap;integrated security=true;";
            conn = null;
        }
        public int ExecuteCommand(string strQuery)
        {
            SqlCommand cmd;
            int result = 0;
            if (conn == null)
                conn = new SqlConnection(strConnect);
            try
            {
                conn.Open();
                cmd = new SqlCommand();
                // gán đối tượng connection vào property connection của command
                cmd.Connection = conn;
                // gán chuỗi command vào property commandtext của command
                cmd.CommandText = strQuery;
                // chọn loạt command
                cmd.CommandType = CommandType.Text;
                // thực hiện command
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Error = ex.Message;
            }

            return result;
        }
    }
}
